# RT-Thread building script for bridge

import os
import rtconfig
Import ('RTT_ROOT')
from building import *

src = []
libs = []
objs = []
libpath = []
cpppath = []
cppdefines = []
cwd = GetCurrentDir()
list = os.listdir(cwd)

cppdefines += ['DAPLINK_VERSION=254'] 
cppdefines += ['HID_ENDPOINT']
cppdefines += ['MSC_ENDPOINT']
cppdefines += ['CDC_ENDPOINT']
cppdefines += ['WEBUSB_INTERFACE']
cppdefines += ['WINUSB_INTERFACE']
cppdefines += ['DRAG_N_DROP_SUPPORT']
cppdefines += ['DAPLINK_IF']
cppdefines += ['DAPLINK_BUILD_KEY=0x9B939E8F']
cppdefines += ['OS_TICK=10000']
cppdefines += ['INTERFACE_STM32F103XB']
cppdefines += ['USE_HAL_DRIVER']
cppdefines += ['STM32F103xB']
cppdefines += ['DAPLINK_HIC_ID=0x97969908']
cppdefines += ['__packed=__packed']
cppdefines += ['DAPLINK_NO_ASSERT_FILENAMES']
cppdefines += ['OS_CLOCK=72000000']
cppdefines += ['BULK_ENDPOINT']

cpppath += [cwd + '/source/usb']
cpppath += [cwd + '/source/daplink']
cpppath += [cwd + '/source/daplink/cmsis-dap']
cpppath += [cwd + '/source/daplink/drag-n-drop']
cpppath += [cwd + '/source/daplink/usb2uart']
cpppath += [cwd + '/source/daplink/settings']
cpppath += [cwd + '/source/daplink/interface']
cpppath += [cwd + '/source/cmsis-core']
cpppath += [cwd + '/source/hic_hal']
cpppath += [cwd + '/source/target']
# cpppath += [cwd + '/source/rtos']
cpppath += [cwd + '/source/hic_hal/stm32/stm32f103xb']
cpppath += [cwd + '/source/hic_hal/stm32/stm32f103xb/cmsis']

# src += ['source/daplink/cmsis-dap/DAP.c']
# src += ['source/daplink/cmsis-dap/DAP_queue.c']
# src += ['source/daplink/cmsis-dap/DAP_vendor.c']
# src += ['source/daplink/cmsis-dap/JTAG_DP.c']
# src += ['source/daplink/cmsis-dap/SW_DP.c']
# src += ['source/daplink/cmsis-dap/SWO.c']
# src += ['source/daplink/interface/bootloader_update.c']
# # src += ['source/daplink/circ_buf.c']
# # src += ['source/daplink/cortex_m.c']
# src += ['source/daplink/crc16.c']
# src += ['source/daplink/crc32.c']
# src += ['source/daplink/interface/daplink.c']
# src += ['source/daplink/error.c']
# src += ['source/daplink/flash_hal.c']
# # src += ['source/daplink/HardFault_Handler.c']
# src += ['source/daplink/info.c']
# src += ['source/daplink/interface/main.c']
# src += ['source/daplink/sdk_stub.c']
# src += ['source/daplink/interface/SVC_Table.s']
# src += ['source/daplink/interface/swd_host.c']
# src += ['source/daplink/interface/swd_host_ca.c']
# src += ['source/daplink/interface/target_flash.c']
# src += ['source/daplink/util.c']
# src += ['source/daplink/validation.c']
# src += ['source/daplink/drag-n-drop/file_stream.c']
# src += ['source/daplink/drag-n-drop/flash_decoder.c']
# src += ['source/daplink/drag-n-drop/flash_intf.c']
# src += ['source/daplink/drag-n-drop/flash_manager.c']
# src += ['source/daplink/drag-n-drop/iap_flash_intf.c']
# src += ['source/daplink/drag-n-drop/intelhex.c']
# src += ['source/daplink/drag-n-drop/vfs_manager.c']
# src += ['source/daplink/drag-n-drop/vfs_user.c']
# src += ['source/daplink/drag-n-drop/virtual_fs.c']
# src += ['source/family/freescale/target_reset_Kseries.c']
# src += ['source/family/freescale/target_reset_Lseries.c']
# src += ['source/family/freescale/target_reset_mimxrt.c']
# src += ['source/family/nordic/target_reset_nrf51.c']
# src += ['source/family/nordic/target_reset_nrf52.c']
# src += ['source/family/freescale/target_reset_rapid_iot.c'] 
# src += ['source/family/realtek/target_reset_realtek_rtl8195am.c']
# src += ['source/family/renesas/target_reset_rza.c']
# src += ['source/family/ti/target_reset_ti.c']
# src += ['source/family/toshiba/target_reset_tz.c']
# src += ['source/family/wiznet/target_reset_wiznet.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/flash.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/gpio.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/read_uid.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/sdk.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/armcc/startup_stm32f103xb.S']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c'] 
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_usart.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/cmsis/system_stm32f1xx.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/uart.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/usb_config.c']
# # src += ['source/hic_hal/stm32/stm32f103xb/usbd_STM32F103.c']

# # src += ['source/rtos/cmsis_os2_port.c']
# # src += ['source/rtos/cm3/HAL_CM3.c']
# # src += ['source/rtos/rt_Event.c']
# # src += ['source/rtos/rt_List.c']
# # src += ['source/rtos/rt_Mailbox.c']
# # src += ['source/rtos/rt_MemBox.c']
# # src += ['source/rtos/rt_Mutex.c']
# # src += ['source/rtos/rt_Robin.c']
# # src += ['source/rtos/rt_Semaphore.c']
# # src += ['source/rtos/rt_System.c']
# # src += ['source/rtos/rt_Task.c']
# # src += ['source/rtos/rt_Time.c']
# # src += ['source/rtos/rt_Timer.c']
# # src += ['source/rtos/RTX_Config.c']
# src += ['source/daplink/settings/settings.c']
# src += ['source/daplink/settings/settings_rom.c']
# src += ['source/target/target_board.c']
# src += ['source/target/target_family.c']
# src += ['source/usb/bulk/usbd_bulk.c']
# src += ['source/usb/cdc/usbd_cdc_acm.c']
# src += ['source/usb/usbd_core.c']
# src += ['source/usb/cdc/usbd_core_cdc.c']
# src += ['source/usb/hid/usbd_core_hid.c']
# src += ['source/usb/msc/usbd_core_msc.c']
# src += ['source/usb/webusb/usbd_core_webusb.c']
# src += ['source/usb/winusb/usbd_core_winusb.c']
# src += ['source/usb/hid/usbd_hid.c']
# src += ['source/usb/msc/usbd_msc.c']
# src += ['source/usb/hid/usbd_user_hid.c']
# src += ['source/daplink/usb2uart/usbd_user_cdc_acm.c']

group = DefineGroup('daplink', src, depend = [''], CPPPATH = cpppath, CPPDEFINES = cppdefines, LIBS = libs, LIBPATH = libpath)

for d in list:
    path = os.path.join(cwd, d)
    if os.path.isfile(os.path.join(path, 'SConscript')):
        objs = objs + SConscript(os.path.join(d, 'SConscript'))
objs = objs + group
Return('objs')
